Home
Ray
Articles
This Old House
Family History
Validate Zip Code
Text Box
Please enter your Zip Code.
SAMPLE CODE
Please enter your Zip Code.
function checkZipCode() { var valueEntered = document.getElementById("idZip").value; var numChars = document.getElementById("idZip").value.length; if (Number(numChars) < 5) { alert("Please enter a 5-digit code."); return false; } for (var i = 0; i <= 4; i++) { var thisChar = parseInt(valueEntered[i]); if (isNaN(thisChar)) { // isNaN is not a number alert("Please enter only numbers."); return false; } } }